package cn.itcast.controller;

import cn.itcast.domain.Standard;
import cn.itcast.service.StandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

//收派标准的控制类
@Controller
public class StandardController {

    @Autowired
    private StandardService standardService;
   // http://localhost:8080/standard_save

    //保存或修改的方法
    @RequestMapping("/standard_save")
    public String save(Standard standard){
     //   for (int i = 0; i < 10; i++) {
        System.out.println("standard========= = " + standard);
        standardService.save(standard);
        //standard.setId(null);
       // }


        //重定向到/pages/base/standard.html";
        return "redirect:/pages/base/standard.html";
    }

    //分页查询所有
    @RequestMapping("/standard_pageQuery")
    @ResponseBody
    public Map fandAllAndPage(int rows,int page){
        Map<String,Object> resultMap=new HashMap();

        Page<Standard> pageAll = standardService.fandAllAndPage(page, rows);

        resultMap.put("total",pageAll.getTotalElements());
        resultMap.put("rows",pageAll.getContent());

        return resultMap;
    }

    //删除选中
    @RequestMapping("/standard_del")
    public String standardDel(String ids){
        standardService.standardDel(ids);
        //重定向到/pages/base/standard.html";
        return "redirect:/pages/base/standard.html";
    }

}
